package com.xinan.weixin.api;

import com.jfinal.kit.HttpKit;
import com.jfinal.weixin.sdk.api.AccessTokenApi;
import com.jfinal.weixin.sdk.api.ApiResult;

/**
 * Created with IntelliJ IDEA.
 * User: xiaojing
 * Date: 14-11-21
 * Time: 下午4:05
 * To change this template use File | Settings | File Templates.
 */
public class NewsApi {
    private static String creatnews = "https://api.weixin.qq.com/cgi-bin/media/uploadnews?access_token=ACCESS_TOKEN";
    private static String sendall = "https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token=ACCESS_TOKEN";
    private static String sendbyid = "https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token=ACCESS_TOKEN";

    /**
     * 上传图文消息素材
     */
    public ApiResult createNews(String jsonStr) {
        String jsonResult = HttpKit.post(creatnews + AccessTokenApi.getAccessToken().getAccessToken(), jsonStr);
        return new ApiResult(jsonResult);
    }

    /**
     * 根据分组进行群发
     */
    public ApiResult sendall(String jsonStr) {
        String jsonResult = HttpKit.post(sendall + AccessTokenApi.getAccessToken().getAccessToken(), jsonStr);
        return new ApiResult(jsonResult);
    }

    /**
     * 根据OpenID列表群发
     */
    public ApiResult sendByid(String jsonStr) {
        String jsonResult = HttpKit.post(sendbyid + AccessTokenApi.getAccessToken().getAccessToken(), jsonStr);
        return new ApiResult(jsonResult);
    }
}
